// 评定页面接口
var strArray = location.search;

// console.log(strArray)
var idStr;
var indexId;
var indexName;
// 获取百分比平分的个数
var percentIndex;
// 获取isMany==attr的值
attrArr = ''
// 获取isMany==0或1时候获取的值
isManyAll = ''



if (strArray.length != 0) {
    idStr = strArray.split("?")[1].split("=")[1];
    supportExpress=strArray.split("?")[2].split("=")[1];
    indexId = strArray.split("?")[3].split("=")[1];
    indexName = strArray.split("?")[4].split("=")[1];
    indexName = getCharFromUtf8(indexName);
} else {
    dialog('网络错误')
}

console.log(supportExpress);
console.log(idStr)
console.log(indexId)
console.log(indexName)


var newTime = timeAll();
// 本类的项目
function ajaxtest() {
    var nameStr = '<div class="topName">' + indexName
        + '</div>';
    $('#topName').append(nameStr)
    var timeStamp = "timeStamp:" + newTime + "BM" + "productId:" + indexId + 'BM';
    var signs = md5(timeStamp);
    signs = signs.toUpperCase();

    $.ajax({
        type: "post",
        url: webUrl + "api/assess/getPhoneInfo",
        data: {
            "timeStamp": newTime,
            "productId": indexId,
            "sign": signs,
        },
        dataType: "JSON",
        async: false,
        success: function (data) {
            $("#content").html(data)
            if (data.status == 200) {
                var str;
                var hh;
                percentIndex = data.data.length;
                for (var i = 0; i < data.data.length; i++) {
                    var liArray;
                    var item = data.data[i];
                    str = '<div>' +
                        '<div class="name-item">' + '&nbsp;' + item.categoryName +
                        '</div>' +
                        '<ul class="ulitem">';
                    if (item.isMany == 'attr') {
                        for (var j = 0; j < item.productStatusList.length; j++) {
                            hh = 'strP' + i;
                            liArray = '<li class="edd"  onclick=ss()>' +
                                '<input class="item2" type="radio"; value=' + item.productStatusList[j].id + ',' + ' &nbsp; name=' + hh + ' data-labelauty=' + item.productStatusList[j].name + '>' +
                                '</li>';
                            str = str + liArray;
                        }
                    } else if (item.isMany == 0) {
                        for (var j = 0; j < item.productStatusList.length; j++) {
                            hh = 'strP' + i;
                            liArray = '<li class="edd"  onclick=ss()>' +
                                '<input class="item2" type="radio" value=' + item.productStatusList[j].id + '|' + ' &nbsp; name=' + hh + ' data-labelauty=' + item.productStatusList[j].name + '>' +
                                '</li>';
                            str = str + liArray;
                        }
                    } else if (item.isMany == 1) {
                        for (var j = 0; j < item.productStatusList.length; j++) {
                            hh = 'strP' + i;
                            if (item.productStatusList[j].name == '无以下问题') {
                                liArray = '<li class="edd">' +
                                    '<input class="item2"  type="checkbox" id="alls" name="itemSs" onclick="selectAll()" value=' + item.productStatusList[j].id + '|' + ' &nbsp;  data-labelauty=' + item.productStatusList[j].name + '>' +
                                    '</li>';
                            } else {
                                liArray = '<li class="edd">' +
                                    '<input class="item2" type="checkbox"  name="itemHh"  onclick="quxiao()" value=' + item.productStatusList[j].id + '|' + ' &nbsp; data-labelauty=' + item.productStatusList[j].name + '>' +
                                    '</li>';
                            }
                            str = str + liArray;
                        }
                    }
                    str = str + '</ul>' +
                        '</div>' + '&nbsp;';
                    $('#content').append(str)
                }
            } else if (data.status == 300) {
                document.location.href = '../html/login.html'
            } else if (data.status == 500) {
                dialog(data.msg);
            }
        },
        error: function (data) {
            //弹出报错内容　　
            dialog("服务器异常")
        }
    });
}


// 百分比动态的改变
function ss() {
    fn();
}


result = "";
var percent = 0;
var selectedPrecent = 0;

// 单选反选
function selectAll() {
    var checkboxs = document.getElementsByName("itemHh");
    var checkboxsssss = $("input[type='checkbox']:checked").length;

    if (checkboxsssss == 0) {
        selectedPrecent = 0;
    } else {
        for (var i = 0; i < checkboxs.length; i++) {
            var e = checkboxs[i];
            if (e.checked === true) {
                e.checked = false;
            }
            else {
                e.checked = false;
            }
        }
        selectedPrecent = 100 - Math.floor(100 / percentIndex) * (percentIndex - 1);
    }

    selectedPrecent = percent + selectedPrecent;
    radialObj.animate(selectedPrecent);
}


// 多选反选
function quxiao() {
    var checkboxs = document.getElementsByName("itemSs");
    var checkboxsqq = document.getElementsByName("itemHh");

    var checkboxsssss = $("input[type='checkbox']:checked").length;

    for (var i = 0; i < checkboxs.length; i++) {
        var e = checkboxs[i];
        if (checkboxsssss === 0) {
            selectedPrecent = 0;
        } else {
            if (e.checked === true) {
                e.checked = false;
            }
            else {
                e.checked = false;
            }
            selectedPrecent = 100 - Math.floor(100 / percentIndex) * (percentIndex - 1);
        }
    }
    selectedPrecent = percent + selectedPrecent;
    radialObj.animate(selectedPrecent);
}

var inpArr = document.getElementsByTagName("input");

// 百分比动态添加
function fn() {
    // 当前总共的个数
    // alert('得到单选之后的值=='+ssdsasda)
    result = "";
    percent = 0;
    var checkboxsssss = $("input[type='checkbox']:checked").length;

    if(checkboxsssss==0){
        selectedPrecent=0;
    }else {
        selectedPrecent = 100 - Math.floor(100 / percentIndex) * (percentIndex - 1);
    }
    for (var i = 0; i < inpArr.length; i++) {
        if (inpArr[i].type == 'radio') {
            if (inpArr[i].checked) {
                result += inpArr[i].value;
                percent += Math.floor(100 / percentIndex);
            }
        }
    }
    radialObj.animate(percent + selectedPrecent);
}


// 重新选择
function choiseClick() {
    radialObj.animate(0);
    $('html,body').animate({
        scrollTop: $("#content").offset().top - 145,
    }, 500);
    for (var i = 0; i < inpArr.length; i++) {
        var e = inpArr[i];
        if (e.checked === true) {
            e.checked = false;
        }
        else {
            e.checked = false;
        }
    }
}


// 查看预估价
function pricesGu() {
    result = "";
    for (var i = 0; i < inpArr.length; i++) {
        if (inpArr[i].checked) {
            result += inpArr[i].value;
        }
    }

    // 获取isMany==attr的值
    attrArr = ''
    // 获取isMany==0或1时候的值
    isManyAll = ''

    var strs = result.split(",");
    // console.log('","分割的数组的个数======'+(strs.length - 1));
    // 获取"，"逗号分割后面的值
    // console.log('","分割后的值======'+strs[strs.length - 1])
    // 将"，"逗号分割后的值进行再次分割
    var strs2 = strs[strs.length - 1].split("|");
    // console.log('"|"分割的数组的个数======'+(strs2.length - 1));
    // 获取"|"竖行分割后的值
    // console.log('"|"分割后的值======'+strs2[strs2.length - 1]);

    for (var i = 0; i < strs.length - 1; i++) {
        if (i == (strs.length - 2)) {
            attrArr += strs[i];
        } else {
            attrArr += strs[i] + ",";
        }
    }
    for (var i = 0; i < strs2.length - 1; i++) {
        if (i == (strs2.length - 2)) {
            isManyAll += strs2[i];
        } else {
            isManyAll += strs2[i] + ",";
        }
    }
    // 获取被选中
    var checkboxsssss = $("input[type='checkbox']:checked").length;

    if(checkboxsssss==0){
        selectedPrecent=0;
    }else {
        selectedPrecent = 100 - Math.floor(100 / percentIndex) * (percentIndex - 1);
    }


    if (percent + selectedPrecent== 100) {
        text();
    } else {
        dialog("请完成所有选项");
        return false;
    }
}


// 查看预估计接口调用
function text() {
    var timeStamp = "timeStamp:" + newTime + "BM" + "attrArr:" +
        attrArr + "BM" + "problemArr:" + isManyAll + "BM" + "storeId:" + idStr + "BM" + "productId:" + indexId + "BM";
    var signs = md5(timeStamp);
    signs = signs.toUpperCase();

    $.ajax({
        type: "post",
        url: webUrl + "/api/beforeResult/price",
        data: {
            "timeStamp": newTime,
            "attrArr": attrArr,
            "problemArr": isManyAll,
            "storeId": idStr,
            "productId": indexId,
            "sign": signs,
        },
        dataType: "JSON",
        async: false,
        success: function (data) {
            if (data.status == 200) {
                document.location.href = '../Result/Result.html?strArray=' +idStr +'?supportExpress='+supportExpress + '?attrArr=' + attrArr + '?problemArr=' + isManyAll +'?productId=' + indexId + '?indexName=' + indexName;
            } else if (data.status == 300) {
                document.location.href = '../login/login.html';
            } else if (data.status == 500) {
                dialog(data.msg);
            }
        },
        error: function (data) {
            //弹出报错内容　　
            dialog("服务器异常")
        }
    })
}



// 圆形指示器控件
var radialObj = radialIndicator('#indicatorContainer', {
    barColor: '#32dac3',
    barWidth: 7,
    initValue: 0
});